import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Enlist from "../views/Enlist.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "Home",
    component: Home,
    children: [
      {
        path: "/home",
        redirect: "/home/homes",
      },
      {
        path: "homes",
        component: () =>
          import(/* webpackChunkName: "homes" */ "../views/home/Homes.vue"),
      },
      {
        path: "allin",
        component: () =>
          import(/* webpackChunkName: "allin" */ "../views/home/Allin.vue"),
      },
      {
        path: "square",
        component: () =>
          import(/* webpackChunkName: "square" */ "../views/home/Square.vue"),
      },
      {
        path: "notice",
        component: () =>
          import(/* webpackChunkName: "notice" */ "../views/home/Notice.vue"),
      },
      {
        path: "my",
        /*   meta: {
          needlogin: true,
        }, */
        component: () =>
          import(/* webpackChunkName: "my" */ "../views/home/My.vue"),
      },
    ],
  },
  {
    path: "/comments",
    name: "Comments",
    component: () => import("../views/comments.vue"),
  },
  {
    path: "/modify",
    name: "Modify",
    meta: {
      title: "个人信息",
    },
    component: () =>
      import(/* webpackChunkName: "modify" */ "../views/Modify.vue"),
  },
  {
    path: "/enlist",
    name: "Enlist",
    component: Enlist,
    children: [
      {
        path: "/enlist",
        redirect: "/enlist/eenlist",
      },
      {
        path: "eenlist",
        component: () =>
          import(
            /* webpackChunkName: "eenlist" */ "../views/enlist/Eenlist.vue"
          ),
      },
      {
        path: "ebaoming",
        component: () =>
          import(
            /* webpackChunkName: "ebaoming" */ "../views/enlist/Ebaoming.vue"
          ),
      },
      {
        path: "edaogang",
        component: () =>
          import(
            /* webpackChunkName: "edaogang" */ "../views/enlist/Edaogang.vue"
          ),
      },
      {
        path: "ejiesuan",
        component: () =>
          import(
            /* webpackChunkName: "ejiesuan" */ "../views/enlist/Ejiesuan.vue"
          ),
      },
      {
        path: "eluyong",
        component: () =>
          import(
            /* webpackChunkName: "eluyong" */ "../views/enlist/Eluyong.vue"
          ),
      },
    ],
  },
  {
    path: "/nothices",
    name: "Nothices",
    meta: {
      title: "客服小姐姐",
    },
    component: () =>
      import(/* webpackChunkName: "my" */ "../views/home/Nothices.vue"),
  },
  {
    path: "/register",
    name: "Register",
    component: () =>
      import(/* webpackChunkName: "my" */ "../views/Register.vue"),
  },
  {
    path: "/setlogin",
    name: "Setlogin",
    component: () =>
      import(/* webpackChunkName: "setlogin" */ "../views/Setlogin.vue"),
  },
  {
    path: "/user",
    name: "User",
    meta: {
      title: "用户协议",
    },
    component: () =>
      import(/* webpackChunkName: "my" */ "../views/agreement/User.vue"),
  },
  {
    path: "/privacy",
    name: "Privacy",
    meta: {
      title: "隐私协议",
    },
    component: () =>
      import(/* webpackChunkName: "my" */ "../views/agreement/Privacy.vue"),
  },
  {
    path: "/service",
    name: "Service",
    meta: {
      title: "联通同意认证服务条款",
    },
    component: () =>
      import(/* webpackChunkName: "my" */ "../views/agreement/Service.vue"),
  },
  {
    path: "/enter",
    name: "Enter",
    component: () => import(/* webpackChunkName: "my" */ "../views/Enter.vue"),
  },
  {
    path: "/jobitem",
    name: "Jobitem",
    meta: {
      title: "工作详情",
    },
    component: () =>
      import(/* webpackChunkName: "my" */ "../components/index/JopItem.vue"),
  },
  {
    path: "/student",
    name: "Student",
    meta: {
      title: "学生兼职",
    },
    component: () =>
      import(
        /* webpackChunkName: "my" */ "../allwork/allrecommend/student.vue"
      ),
  },
  {
    path: "/smartphone",
    name: "Smartphone",
    meta: {
      title: "手机兼职",
    },
    component: () =>
      import(
        /* webpackChunkName: "my" */ "../allwork/allrecommend/smartphone.vue"
      ),
  },
  {
    path: "/business",
    name: "Business",
    meta: {
      title: "企业直招",
    },
    component: () =>
      import(
        /* webpackChunkName: "my" */ "../allwork/allrecommend/business.vue"
      ),
  },
  {
    path: "/select",
    name: "Select",
    meta: {
      title: "严选兼职",
    },
    component: () =>
      import(/* webpackChunkName: "my" */ "../allwork/allrecommend/select.vue"),
  },
  {
    path: "/holiday",
    name: "Holiday",
    meta: {
      title: "暑假兼职",
    },
    component: () =>
      import(
        /* webpackChunkName: "my" */ "../allwork/allrecommend/holiday.vue"
      ),
  },

  {
    path: "/jifen",
    name: "Jifen",
    meta: {
      title: "积分换好礼",
    },
    component: () =>
      import(/* webpackChunkName: "jifen" */ "../views/Jifen.vue"),
  },
  {
    path: "/kajuan",
    name: "Kajuan",
    meta: {
      title: "兼职卡卷",
    },
    component: () =>
      import(/* webpackChunkName: "kajuan" */ "../views/Kajuan.vue"),
  },
  {
    path: "/qianbao",
    name: "Qianbao",
    meta: {
      title: "我的钱包",
      text: "要保护好自己的钱包哦！！！",
    },
    component: () =>
      import(/* webpackChunkName: "qianbao" */ "../views/Qianbao.vue"),
  },
  {
    path: "/qiuzhi",
    name: "Qiuzhi",
    meta: {
      title: "求职意向",
      text: "设置求职意向,会按你的需求给你匹配合适的兼职",
    },
    component: () =>
      import(/* webpackChunkName: "qiuzhi" */ "../views/Qiuzhi.vue"),
  },
  {
    path: "/shoucang",
    name: "Shoucang",
    meta: {
      title: "我的收藏",
      text: "收藏起来！！！到时候使用",
    },
    component: () =>
      import(/* webpackChunkName: "shoucang" */ "../views/Shoucang.vue"),
  },
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
});

/* function isLogin() {
  return sessionStorage.getItem("uid") ? true : false;
}

router.beforeEach((to, from, next) => {
  // to and from are both route objects. must call `next`.
  if (to.meta.needlogin) {
    if (isLogin()) {
      next();
    } else {
      next({
        name: "Enter",
      });
    }
  } else {
    next();
  }
}); */

export default router;
